package com.situ.fly.interceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Component;
/**
 * 
 * 用户拦截器
 */
import org.springframework.web.servlet.HandlerInterceptor;

import com.situ.fly.entity.User;
@Component
public class UserInterceptor implements HandlerInterceptor {

	
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		// TODO Auto-generated method stub
		//判断用户是否登录
		HttpSession session=request.getSession();
		
		User user=(User) session.getAttribute("user");
		
		if (user==null) {
			response.sendRedirect("/user/login");
			return false;
			
		}else {//用户已经登录
			return true;//放行
		}
		
		
	}
}
